#@layout()

#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        <div id="datagridId"></div>

        <div id="datagridTb">
            <div class="row">
                <div class="col-md-12">
                    <form id="searchForm">
                        <div class="easyui-panel" title="信息查询" style="width:100%;padding:10px;"
                             data-options="iconCls:'icon-application_form'">

                            #(_res.get('user.form.username')): <input class="easyui-textbox" id="userName"
                                                                      style="width:200px">&nbsp;&nbsp;
                            #(_res.get('fidolog.form.transeq')): <input class="easyui-textbox" id="transeq"
                                                                        style="width:200px">&nbsp;&nbsp;
                            #(_res.get('fidolog.form.opererror')): <input class="easyui-textbox" id="operError"
                                                                          style="width:200px">&nbsp;&nbsp;
                            认证类型：
                            <select name="authType" id="authType" class="easyui-combobox"
                                    data-options="editable: false">
                                <option value="" selected>全部</option>
                                #for(dict : authTypeListForJS)
                                <option value="#(dict.dictText)">#(dict.dictName)</option>
                                #end
                            </select>&nbsp;&nbsp;
                            开始时间: <input class="easyui-datebox" id="startTime"  data-options="editable:false" style="width:200px">&nbsp;&nbsp;
                            结束时间: <input class="easyui-datebox" id="endTime"  data-options="editable:false" style="width:200px">&nbsp;&nbsp;

                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                               onclick="datagridQuery();" iconCls="icon-zoom">#(_res.get('system.common.search'))</a>
                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true"
                               onclick="$('#searchForm').form('clear');" iconCls="icon-zoom_out">#(_res.get('system.common.clear'))</a>
                        </div>
                    </form>
                </div>
                <div class="row">
                    <div class="col-md-12" style="padding: 5px 25px;">
                        #for(resource : resourceList)
                        <a href="javascript:;" class="easyui-linkbutton"
                           data-options="iconCls:'#(resource.icon)',plain:true" id='#(resource.url)'>#(_res.get(resource.resourceName))</a>
                        #end
                    </div>
                </div>
            </div>
        </div>
    </div>


</div>

#end


#define css()

#end


#define js()

<script type="text/javascript">

    var _datagrid = "datagridId", _form = "formId", _datagridTb = "datagridTb";
    var datagridListUrl = contextRootPath + '/fidoLog/list';

    $(function () {

        //初始化表格
        $("#" + _datagrid).datagrid({
            url: datagridListUrl,
            fit: true,
            border: false,
            rownumbers: true,
            pageSize: 30,
            toolbar: '#' + _datagridTb,
            singleSelect: true,
            pagination: true,
            nowrap: false,
            striped: true,
            fitColumns: true,
            checkOnSelect: false,
            onClickRow: function (rowIndex, rowData) {
                $(this).datagrid('unselectRow', rowIndex);
            },
            onLoadSuccess: function (data) {
                if (data.total === 30000) {
                    $(".pagination-info").prepend("<span style='color:red;margin-right:15px;'>查询结果大约30000条,请缩小查询范围</span>");
                }
                $("#startTime").datebox("setValue", data.startTime);
                $("#endTime").datebox("setValue", data.endTime);
                //alert(data.startTime);
                //alert(data.endTime);
            },
            columns: [[
                {
                    field: DbLogConst.TABLE_FIDO_LOG.FL_ID,
                    title: DbLogConst.TABLE_FIDO_LOG.FL_ID,
                    checkbox: true
                },
                {
                    field: DbLogConst.TABLE_FIDO_LOG.TRANSEQ,
                    title: "#(_res.get('fidolog.form.transeq'))"
                }
                ,
                {
                    field: DbLogConst.TABLE_FIDO_LOG.USER_NAME,
                    title: "#(_res.get('user.form.username'))"
                }
                ,
                {
                    field: DbLogConst.TABLE_FIDO_LOG.OPER_TYPE,
                    title: "#(_res.get('fidolog.form.opertype'))",
                    formatter: function (value, row, index) {
                        return getOperType(row.oper_type);
                    }
                }
                ,
                {
                    field: DbLogConst.TABLE_FIDO_LOG.OPER_CODE,
                    title: "#(_res.get('fidolog.form.opercode'))"
                }
                ,
                {
                    field: DbLogConst.TABLE_FIDO_LOG.REMOTE_IP,
                    title: "#(_res.get('fidolog.form.remoteip'))"
                }
                ,
                {
                    field: 'createts',
                    title: "#(_res.get('fidolog.form.creates'))"
                }
                ,
                {
                    field: 'request',
                    title: "请求数据",
                    formatter: function (value, row, index) {
                        //return value;
                        return '<a href=\'javascript:void(0);\' onclick=\'displayFidoRequest(this)\' class=\'easyui-linkbutton\' value=\'' + row.fl_id + '\'>请求数据</a>';
                    }
                }
                ,
                {
                    field: 'response',
                    title: "响应数据",
                    formatter: function (value, row, index) {
                        return '<a href=\'javascript:void(0);\' onclick=\'displayFidoResponse(this)\' class=\'easyui-linkbutton\' value=\'' + row.fl_id + '\'>响应数据</a>';
                    }
                }
                ,
                {
                    field: DbLogConst.TABLE_FIDO_LOG.OPER_ERROR,
                    title: "#(_res.get('fidolog.form.opererror'))"
                }
                ,
                {
                    field: DbLogConst.TABLE_FIDO_LOG.LOCAL_IP,
                    title: "#(_res.get('fidolog.form.localip'))"
                }
            ]]
        });
    });

    function datagridQuery() {
        var userName = $("#userName");
        var transeq = $("#transeq");
        var operError = $("#operError");

        var flag = $("#searchForm").form('enableValidation').form('validate');

        if (!flag) return;

        $("#" + _datagrid).datagrid({
            queryParams: {
                "fidoLog.user_name": userName.val(),
                "fidoLog.transeq": transeq.val(),
                "fidoLog.oper_error": operError.val(),
                'start_time': $('#startTime').val(),
                'end_time': $('#endTime').val(),
                'fidoLog.auth_type': $('#authType').val()
            }
        });
    }


    function displayFidoInfo(obj) {
        var value = obj.getAttribute("value");
        try {
            console.log(value);
            var v = formatJson(value);
        } catch (e) {
            $.messager.alert("提示框", "数据太长，请到数据库中查看", "warning");
            return;
        }
        var element = $('<div></div>');
        element.attr('id', 'fidoInfoDlg');
        element.appendTo(document.body);
        element.dialog({
            title: '详细信息',
            content: '<pre style="width: 100%;line-height: 1.5em;">' + formatJson(value) + '</pre>',
            width: $(window).width() - 50,
            height: $(window).height() - 50,
            modal: true,
            onClose: function () {
                $(this).dialog("destroy");
            }
        });
    }

    function displayFidoRequest(obj) {
        var value = obj.getAttribute("value");
        try {
            var result;
            $.ajax({
                type: 'get',
                url: contextRootPath + "/fidoLog/info",
                data: {'flID': value,'infoType':'1'},
                async: false,
                dataType: 'json',
                success: function (data) {
                    result = data;
                }
            });
            console.log(value+','+result);
            var v = formatJson(result);
        } catch (e) {
            $.messager.alert("提示框", "数据太长，请到数据库中查看", "warning");
            return;
        }
        var element = $('<div></div>');
        element.attr('id', 'fidoInfoDlg');
        element.appendTo(document.body);
        element.dialog({
            title: '详细信息',
            content: '<pre style="width: 100%;line-height: 1.5em;">' + formatJson(result) + '</pre>',
            width: $(window).width() - 50,
            height: $(window).height() - 50,
            modal: true,
            onClose: function () {
                $(this).dialog("destroy");
            }
        });
    }

    function displayFidoResponse(obj) {
        var value = obj.getAttribute("value");
        try {
            var result;
            $.ajax({
                type: 'get',
                url: contextRootPath + "/fidoLog/info",
                data: {'flID': value,'infoType':'2'},
                async: false,
                dataType: 'json',
                success: function (data) {
                    result = data;
                }
            });
            console.log(value+','+result);
            var v = formatJson(result);
        } catch (e) {
            $.messager.alert("提示框", "数据太长，请到数据库中查看", "warning");
            return;
        }
        var element = $('<div></div>');
        element.attr('id', 'fidoInfoDlg');
        element.appendTo(document.body);
        element.dialog({
            title: '详细信息',
            content: '<pre style="width: 100%;line-height: 1.5em;">' + formatJson(result) + '</pre>',
            width: $(window).width() - 50,
            height: $(window).height() - 50,
            modal: true,
            onClose: function () {
                $(this).dialog("destroy");
            }
        });
    }

    //格式化代码函数,已经用原生方式写好了不需要改动,直接引用就好
    var formatJson = function (json, options) {
        var reg = null,
            formatted = '',
            pad = 0,
            PADDING = '    ';
        options = options || {};
        options.newlineAfterColonIfBeforeBraceOrBracket = (options.newlineAfterColonIfBeforeBraceOrBracket === true) ? true : false;
        options.spaceAfterColon = (options.spaceAfterColon === false) ? false : true;
        if (typeof json !== 'string') {
            json = JSON.stringify(json);
        } else {
            json = JSON.parse(json);
            json = JSON.stringify(json);
        }
        reg = /([\{\}])/g;
        json = json.replace(reg, '\r\n$1\r\n');
        reg = /([\[\]])/g;
        json = json.replace(reg, '\r\n$1\r\n');
        reg = /(\,)/g;
        json = json.replace(reg, '$1\r\n');
        reg = /(\r\n\r\n)/g;
        json = json.replace(reg, '\r\n');
        reg = /\r\n\,/g;
        json = json.replace(reg, ',');
        if (!options.newlineAfterColonIfBeforeBraceOrBracket) {
            reg = /\:\r\n\{/g;
            json = json.replace(reg, ':{');
            reg = /\:\r\n\[/g;
            json = json.replace(reg, ':[');
        }
        if (options.spaceAfterColon) {
            reg = /\:/g;
            json = json.replace(reg, ':');
        }
        (json.split('\r\n')).forEach(function (node, index) {
                var i = 0,
                    indent = 0,
                    padding = '';

                if (node.match(/\{$/) || node.match(/\[$/)) {
                    indent = 1;
                } else if (node.match(/\}/) || node.match(/\]/)) {
                    if (pad !== 0) {
                        pad -= 1;
                    }
                } else {
                    indent = 0;
                }

                for (i = 0; i < pad; i++) {
                    padding += PADDING;
                }

                formatted += padding + node + '\r\n';
                pad += indent;
            }
        );
        return formatted;
    };

</script>

#end



